package com.vt.file.controller;

import com.vt.common.base.ResultData;
import com.vt.common.param.file.Base64UploadRequestParam;
import com.vt.file.service.FastDFSClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 文件上传控制类
 */
@RequestMapping(value = "upload")
@RestController
public class FileController {
    @Autowired
    private FastDFSClientService fastDFSClientService;

    /**
     * base64加密上传
     * @param param
     * @return
     */
    @PostMapping(value = "base64")
    public ResultData uploadByBase64(@RequestBody Base64UploadRequestParam param) {
        return fastDFSClientService.uploadFile(param);
    }

    /**
     * 文件形式上传
     * @param file
     * @return
     * @throws IOException
     */
    @PostMapping(value = "multipart")
    public ResultData upload(@RequestParam(value = "file", required = false) MultipartFile file) {
        return fastDFSClientService.multpart(file);
    }

    /**
     * 文件形式上传
     * @param file
     * @return
     * @throws IOException
     */
    @GetMapping(value = "test")
    public ResultData test(){
        return ResultData.ok("http://10.10.10.110:8080/img/a2.jpg");
    }
}
